// index.js
// 获取应用实例
const app = getApp()
const DB = wx.cloud.database().collection("list")
let school=""
let age=""
let delid=""
let upid=""
let upname=""

Page({
  //first cloud function
  data:{
    ne:[]
  },
  qiuhe(){
    wx.cloud.callFunction({
      name: "add",
      data: {
        x:2,
        y:3
      },
      success(res){
        console.log("成功",res)
      },
      fial(res){
        console.log("失败",res)
      }
    })
  },
  topic(){
    wx.navigateTo({
      url: '../pics/pics'
    })
  },
  tolog(){
    
  wx.navigateTo({
    url: '../logs/logs'
  })
  },
  addSchool(event){
    //console.log(event.detail.value)
    school=event.detail.value
  },
  addYears(event){
    age=event.detail.value
  },
  delinput(num){
    delid=num.detail.value
  },
  deleteData(){
    DB.doc(delid).remove({
      success(res){
        console.log("删除成功",res)
      },
      fail(res)
      {
        console.log("删除失败",res)
      }
    })
  },
  //增加数据
  addData(){
    DB.add({
      data:{
        name:"coxhin",
        school: school,
        years: age,
      },
      success(res)
      {
        console.log("增加成功",res)
      },
      fail(res)
      {
        console.log("增加失败",res)
      }
      
    })
  },
  getData(){
    DB.get({
      message:2,
      success(res){
        console.log("查询成功",res.data)
        this.setData({
          ne:res.data
        })
      },
      fail(res)
      {
        console.log("查询失败",res)
      }
    })
  },
  upinput1(event)
  {
    upid=event.detail.value
  },
  upinput2(event)
  {
    upname=event.detail.value
  },
  updateData()
  {
    DB.doc(upid).update({
      data:{
        //name:_.set(upname)
        name:upname
      },
      success(res)
      {
        console.log("更新成功",res)
      },
      fail(res)
      {
        console.log("更新失败",res)
      }
    })
    
  }
})
